package mp;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ms.education.R;
import com.ms.education.course.CourseApplication;
import com.ms.education.course.entity.*;
import com.ms.education.course.entity.vo.ClassTeacherVo;
import com.ms.education.course.entity.vo.CourseResultVo;
import com.ms.education.course.entity.vo.PageCourseVo;
import com.ms.education.course.service.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
 * <p>Project:education-test
 * <p>Powered by ms on 2023-01-17 00:09:12
 *
 * @author ms
 * @version 1.0
 * @since 1.8
 */
@SpringBootTest(classes = CourseApplication.class)
public class test {

    @Autowired
    private ClassroomService classroomService;

    @Autowired
    private ClassUserService classUserService;

    @Autowired
    private PushScheduleService pushScheduleService;

    String cover = "https://msjava.oss-cn-qingdao.aliyuncs.com/2022/05/19/a0f48d8e430c400888570501689f0e4b.jpeg";
    Integer[][] subjects = {{3, 2}, {4, 2}, {9, 5}, {8, 5}};
    //课程状态 Draft未发布  Normal已发布
    String[] status = {"Draft", "Normal"};
    String[] title = {"java基础课程", "XHTML CSS2 JS整站制作教程课程学习", "HTML5入门课程学习", "TCP/IP网络编程"};
    String[][] teacher = {{"1", "张琳"}, {"2", "陈卓"}, {"3", "高巧林"}, {"4", "谢佳乐"}, {"5", "余伊点"}};
    String[] descriptions = {"<p>注重性教育</p>\n" +
            "<table style=\"border-collapse: collapse; width: 100%;\" border=\"1\">\n" +
            "<tbody>\n" +
            "<tr>\n" +
            "<td style=\"width: 16.6667%;\">&nbsp;</td>\n" +
            "<td style=\"width: 16.6667%;\">&nbsp;</td>\n" +
            "<td style=\"width: 16.6667%;\">&nbsp;</td>\n" +
            "<td style=\"width: 16.6667%;\">&nbsp;</td>\n" +
            "<td style=\"width: 16.6667%;\">&nbsp;</td>\n" +
            "</tr>\n" +
            "<tr>\n" +
            "<td style=\"width: 16.6667%;\">&nbsp;</td>\n" +
            "<td style=\"width: 16.6667%;\">&nbsp;</td>\n" +
            "<td style=\"width: 16.6667%;\">&nbsp;</td>\n" +
            "<td style=\"width: 16.6667%;\">&nbsp;</td>\n" +
            "<td style=\"width: 16.6667%;\">&nbsp;</td>\n" +
            "</tr>\n" +
            "<tr>\n" +
            "<td style=\"width: 16.6667%;\">&nbsp;</td>\n" +
            "<td style=\"width: 16.6667%;\">&nbsp;</td>\n" +
            "<td style=\"width: 16.6667%;\">&nbsp;</td>\n" +
            "<td style=\"width: 16.6667%;\">&nbsp;</td>\n" +
            "<td style=\"width: 16.6667%;\">&nbsp;</td>\n" +
            "</tr>\n" +
            "</tbody>\n" +
            "</table>\n" +
            "<p>&nbsp;</p>", "我的测试", "<p>蒋敏老师授课</p>"};

    @Autowired
    private CourseService courseService;

    @Autowired
    private CourseDescriptionService courseDescriptionService;

    @Test
    public void addSomeCourse() {
        LinkedList<Course> courses = new LinkedList<>();
        LinkedList<CourseDescription> courseDescriptions = new LinkedList<>();

        for (int i = 0; i < 10; i++) {
            Course course = new Course();
            course.setCover(cover);
            course.setStatus(status[RandomUtil.randomInt(0, 2)]);
            Integer[] subject = subjects[RandomUtil.randomInt(0, 4)];
            course.setSubjectId(subject[0]);
            course.setSubjectParentId(subject[1]);

            course.setTitle(title[RandomUtil.randomInt(0, 4)]);

            String[] t = teacher[RandomUtil.randomInt(0, 5)];
            course.setTeacherId(Integer.parseInt(t[0]));
            course.setTeacherName(t[1]);

            courses.add(course);

            CourseDescription courseDescription = new CourseDescription();
            courseDescription.setCourseId(i + 1);
            courseDescription.setDescription(descriptions[RandomUtil.randomInt(0, 3)]);
            courseDescriptions.add(courseDescription);
        }

        courseService.saveBatch(courses);
        courseDescriptionService.saveBatch(courseDescriptions);

    }

    @Test
    public void testPageCourse() {
        PageCourseVo pageCourseVo = new PageCourseVo();
        pageCourseVo.setIsContainComment(true);
        pageCourseVo.setIsContainChapter(true);

    }

    @Test
    public void test02() {
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id", 10);
        List<Course> list = courseService.list(wrapper);
        System.out.println(list == null);
    }

    @Test
    public void test03() {
        List<Classroom> classrooms = classroomService.getClassOfUser(701);
        System.out.println(classrooms);
    }

    //测试查询班级讲师
    @Test
    public void test04() {
        List<ClassTeacherVo> classTeacher = classroomService.getClassTeacher(1);
        System.out.println("===============" + classTeacher);
    }

    //测试查询班级用户id
    @Test
    public void test05() {
        System.out.println(classUserService.getClassUserIds(1));
    }

    //测试删除班级学员关系表
    @Test
    public void test06() {
        ArrayList<ClassUser> classUsers = new ArrayList<>();
        ClassUser classUser = new ClassUser();
        classUser.setClassId(1);
        classUser.setUserId(701);
        classUsers.add(classUser);
        ClassUser classUser2 = new ClassUser();
        classUser2.setClassId(1);
        classUser2.setUserId(702);
        classUsers.add(classUser2);
        classUserService.deleteClassUser(classUsers);
    }

    //测试查看今日推送计划
    @Test
    public void test07() {
        QueryWrapper<PushSchedule> wrapper = new QueryWrapper<>();
        wrapper.eq("push_date", DateUtil.today());
        System.out.println("--=-=-=-=" + pushScheduleService.list(wrapper));
    }

    @org.junit.Test
    public void test08(){
        String s1="2023-03-07";
        String s2="2023-03-08";

    }
}
